package org.mall.modules.statistics.controller.admin;

import lombok.extern.slf4j.Slf4j;
import org.mall.common.api.vo.Result;
import org.mall.common.util.MapSortUtil;
import org.mall.modules.member.service.IMemberService;
import org.mall.modules.order.service.OrderService;
import org.mall.modules.product.service.ICommoditySpuService;
import org.mall.modules.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @Auther: LL
 * @Date: 2020/1/6 16:25
 */
@RestController
@RequestMapping("/adminChart")
@Slf4j
public class AdminController {
    @Autowired
    ShopService shopService;
    @Autowired
    IMemberService iMemberService;
    @Autowired
    OrderService orderService;
    @Autowired
    ICommoditySpuService iCommoditySpuService;
    @GetMapping("/allData")
    public Result<?> getAllData(){
        Map<String, Object> resutMap=new HashMap<>();
        Integer shopCount=shopService.getShopCount();
        Integer memberCount=iMemberService.getMemberCount();
        Integer orderCount=orderService.getOrderCount();
        Integer productCount=iCommoditySpuService.getProductCount();
        resutMap.put("shopCount",shopCount.toString());
        resutMap.put("memberCount",memberCount.toString());
        resutMap.put("orderCount",orderCount.toString());
        resutMap.put("productCount",productCount.toString());
        return Result.ok(resutMap);
    }
    @GetMapping("/yearAllShop")
    public Result<?> getYearAllShop(){
        Map<String, Integer> resultMap = null;
        Map<String, Integer> stringIntegerMap = null;
        int[] result={0,0,0,0,0,0,0,0,0,0,0,0};
        try {
            resultMap = shopService.getYearAllShop();
            Iterator<String> iterator=resultMap.keySet().iterator();
            while (iterator.hasNext()){
                String key=iterator.next();
                int index=Integer.parseInt(key);
                result[index]=resultMap.get(key);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.ok(result);
    }

}
